package com.shanzmoo.admin.web.store;

import com.shanzmoo.admin.domain.dto.StoreReceiveBillSaveDTO;
import com.shanzmoo.admin.domain.dto.StoreReceiveBillUpdateDTO;
import com.shanzmoo.admin.manager.store.StoreReceiveBillManager;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.db.store.entity.bo.StoreReceiveSkuSelectBO;
import com.shanzmoo.db.store.entity.query.StoreReceiveBillQuery;
import com.shanzmoo.db.store.entity.vo.StoreReceiveBillVO;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import java.util.List;

/**
 * 仓库收货单 控制层
 *
 * @author Gzhao 2021-03-11
 */
@Api(tags = "仓库-收货单")
@RestController
@RequestMapping("/store/receive-bill")
public class StoreReceiveBillController {

    @Autowired
    private StoreReceiveBillManager storeReceiveBillManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<StoreReceiveBillVO>> pageList(@Valid @RequestBody StoreReceiveBillQuery query) {
        PageRespBase<StoreReceiveBillVO> pageList = storeReceiveBillManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody StoreReceiveBillSaveDTO saveDto) {
        storeReceiveBillManager.saveReceiveBill(saveDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "取消")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
        SResponse<Boolean> re = storeReceiveBillManager.cancel(id);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody StoreReceiveBillUpdateDTO updateDto) {
        storeReceiveBillManager.saveReceiveBill(updateDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/info")
    public SHttpResponse<StoreReceiveBillVO> info(@RequestParam(value = "id") Integer id) {
        SResponse<StoreReceiveBillVO> re = storeReceiveBillManager.getInfo(id);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "审核通过")
    @GetMapping("/examine")
    public SHttpResponse<Boolean> examine(@RequestParam(value = "id") Integer id) {
        SResponse<Boolean> re = storeReceiveBillManager.examine(id);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "待选择商品列表")
    @GetMapping("/getReceiveList")
    public SHttpResponse<List<StoreReceiveSkuSelectBO>> getReceiveList(
            @ApiParam(value = "单据类型") @RequestParam(value = "originOrderType") Integer originOrderType,
            @ApiParam(value = "单据号") @RequestParam(value = "originOrder") String originOrder
    ) {
        List<StoreReceiveSkuSelectBO> re = storeReceiveBillManager.getReceiveList(originOrderType, originOrder);
        return SHttpResponse.ok(re);
    }
}
